<?php
$a = $_REQUEST['a'];
switch ($a) {
	case 'add':
		// err('操作失败');
		ok('操作成功','http://baidu.com');
		break;
	
	case 'delete':
		ok('删除成功');
		break;
}
	
/**
 * @param string $msg
 * @param null $url
 * @param string $data
 * @param int $wait
 * descript 失败返回
 */
function ok($msg = '', $url = null, $data = ''){
    if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
        $url = $_SERVER["HTTP_REFERER"];
    } elseif ('' !== $url) {
        $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : U($url);
    }
    $result = [
        'code' => 1,
        'msg'  => $msg,
        'data' => $data,
        'url'  => $url,
    ];
    echo json_encode($result,JSON_UNESCAPED_UNICODE);die;
}

/**
 * @param string $msg
 * @param null $url
 * @param string $data
 * @param int $wait
 * descript 失败返回
 */
function err($msg = '', $url = null, $data = ''){
    if (!is_null($url)) {
        $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : U($url);
    }
    $result = [
        'code' => 0,
        'msg'  => $msg,
        'data' => $data,
        'url'  => $url,
    ];
    echo json_encode($result,JSON_UNESCAPED_UNICODE);die;
}	


